
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>熔断器-Hystrix · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-sidebar-style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="12.网关-Gateway.html" />
    
    
    <link rel="prev" href="10.服务调用-OpenFeign.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    前言
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">基础篇</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../java基础/IO流基础.html">
            
                <a href="../java基础/IO流基础.html">
            
                    
                    IO流基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../java基础/集合.html">
            
                <a href="../java基础/集合.html">
            
                    
                    集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../java基础/异常处理.html">
            
                <a href="../java基础/异常处理.html">
            
                    
                    异常处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../java基础/线程.html">
            
                <a href="../java基础/线程.html">
            
                    
                    线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="../java基础/网络编程.html">
            
                <a href="../java基础/网络编程.html">
            
                    
                    网络编程
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">进阶篇</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../java进阶/MySQL.html">
            
                <a href="../java进阶/MySQL.html">
            
                    
                    MySQL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../java进阶/Oracle.html">
            
                <a href="../java进阶/Oracle.html">
            
                    
                    Oracle
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../java进阶/Redis.html">
            
                <a href="../java进阶/Redis.html">
            
                    
                    Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../java进阶/Netty.html">
            
                <a href="../java进阶/Netty.html">
            
                    
                    Netty
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="../java进阶/Spring.html">
            
                <a href="../java进阶/Spring.html">
            
                    
                    Spring
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="../java进阶/SpringMVC.html">
            
                <a href="../java进阶/SpringMVC.html">
            
                    
                    SpringMVC
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="../java进阶/单元测试.html">
            
                <a href="../java进阶/单元测试.html">
            
                    
                    SpringBoot单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="../java进阶/设计模式.html">
            
                <a href="../java进阶/设计模式.html">
            
                    
                    二十三个设计模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.8.1" data-path="../java进阶/工厂模式.html">
            
                <a href="../java进阶/工厂模式.html">
            
                    
                    工厂模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.2" data-path="../java进阶/单例模式.html">
            
                <a href="../java进阶/单例模式.html">
            
                    
                    单例模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.3" data-path="../java进阶/建造者模式.html">
            
                <a href="../java进阶/建造者模式.html">
            
                    
                    建造者模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.4" data-path="../java进阶/原型模式.html">
            
                <a href="../java进阶/原型模式.html">
            
                    
                    原型模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.5" data-path="../java进阶/适配器模式.html">
            
                <a href="../java进阶/适配器模式.html">
            
                    
                    适配器模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.6" data-path="../java进阶/责任链模式.html">
            
                <a href="../java进阶/责任链模式.html">
            
                    
                    责任链模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.7" data-path="../java进阶/桥接模式.html">
            
                <a href="../java进阶/桥接模式.html">
            
                    
                    桥接模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">高级篇</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="1.cloud架构选型.html">
            
                <a href="1.cloud架构选型.html">
            
                    
                    Spring Cloud
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="2.Provider-支付模块.html">
            
                <a href="2.Provider-支付模块.html">
            
                    
                    Provider-支付模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="3.Consumer-订单模块.html">
            
                <a href="3.Consumer-订单模块.html">
            
                    
                    Consumer-订单模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.3" data-path="4.重构-Common模块.html">
            
                <a href="4.重构-Common模块.html">
            
                    
                    重构-Common模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.4" data-path="5.注册中心-Enreka.html">
            
                <a href="5.注册中心-Enreka.html">
            
                    
                    注册中心-Enreka
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.5" data-path="6.负载均衡-@LoadBalance.html">
            
                <a href="6.负载均衡-@LoadBalance.html">
            
                    
                    负载均衡-@LoadBalance
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.6" data-path="7.更换注册中心-Zookeeper.html">
            
                <a href="7.更换注册中心-Zookeeper.html">
            
                    
                    更换注册中心-Zookeeper
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.7" data-path="8.更换注册中心-Consul.html">
            
                <a href="8.更换注册中心-Consul.html">
            
                    
                    更换注册中心-Consul
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.8" data-path="9.负载均衡-Ribbon.html">
            
                <a href="9.负载均衡-Ribbon.html">
            
                    
                    负载均衡-Ribbon
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.9" data-path="10.服务调用-OpenFeign.html">
            
                <a href="10.服务调用-OpenFeign.html">
            
                    
                    服务调用-OpenFeign
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="4.1.10" data-path="11.熔断器-Hystrix.html">
            
                <a href="11.熔断器-Hystrix.html">
            
                    
                    熔断器-Hystrix
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.11" data-path="12.网关-Gateway.html">
            
                <a href="12.网关-Gateway.html">
            
                    
                    网关-Gateway
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.12" data-path="13.配置中心-Config.html">
            
                <a href="13.配置中心-Config.html">
            
                    
                    配置中心-Config
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.13" data-path="14.消息总线-bus.html">
            
                <a href="14.消息总线-bus.html">
            
                    
                    消息总线-Bus
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.14" data-path="15.消息驱动-stream.html">
            
                <a href="15.消息驱动-stream.html">
            
                    
                    消息驱动-Stream
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.15" data-path="16.链路监控-Sleuth.html">
            
                <a href="16.链路监控-Sleuth.html">
            
                    
                    链路监控-Sleuth
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.16" data-path="17.注册中心&配置中心-nacos.html">
            
                <a href="17.注册中心&配置中心-nacos.html">
            
                    
                    注册中心&配置中心-nacos
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.17" data-path="18.限流-sentinel.html">
            
                <a href="18.限流-sentinel.html">
            
                    
                    限流-sentinel
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="../java高级/JUC.html">
            
                <a href="../java高级/JUC.html">
            
                    
                    神秘的JUC包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="../java高级/Docker.html">
            
                <a href="../java高级/Docker.html">
            
                    
                    Docker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="../java高级/布隆过滤器.html">
            
                <a href="../java高级/布隆过滤器.html">
            
                    
                    布隆过滤器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="../java高级/Redission.html">
            
                <a href="../java高级/Redission.html">
            
                    
                    Redission
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="../java高级/MQ.html">
            
                <a href="../java高级/MQ.html">
            
                    
                    消息队列
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="../java高级/JVM.html">
            
                <a href="../java高级/JVM.html">
            
                    
                    JVM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="../java书籍/《Effective Java》读书笔记.html">
            
                <a href="../java书籍/《Effective Java》读书笔记.html">
            
                    
                    《Effective Java》读书笔记 
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.8.1" data-path="../java书籍/创建和销毁对象.html">
            
                <a href="../java书籍/创建和销毁对象.html">
            
                    
                    创建和销毁对象
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">番外篇</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../java面试/面试题.html">
            
                <a href="../java面试/面试题.html">
            
                    
                    面试题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../番外篇/小程序.html">
            
                <a href="../番外篇/小程序.html">
            
                    
                    微信小程序
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >熔断器-Hystrix</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h3 id="1&#x5206;&#x5E03;&#x5F0F;&#x7CFB;&#x7EDF;&#x5B58;&#x5728;&#x7684;&#x95EE;&#x9898;"><a name="1&#x5206;&#x5E03;&#x5F0F;&#x7CFB;&#x7EDF;&#x5B58;&#x5728;&#x7684;&#x95EE;&#x9898;" class="plugin-anchor" href="#1&#x5206;&#x5E03;&#x5F0F;&#x7CFB;&#x7EDF;&#x5B58;&#x5728;&#x7684;&#x95EE;&#x9898;"><i class="fa fa-link" aria-hidden="true"></i></a>1.&#x5206;&#x5E03;&#x5F0F;&#x7CFB;&#x7EDF;&#x5B58;&#x5728;&#x7684;&#x95EE;&#x9898;</h3>
<p>&#x590D;&#x6742;&#x5206;&#x5E03;&#x5F0F;&#x4F53;&#x7CFB;&#x7ED3;&#x6784;&#x4E2D;&#x7684;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x6709;&#x6570;&#x5341;&#x4E2A;&#x4F9D;&#x8D56;&#x5173;&#x7CFB;&#xFF0C;&#x6BCF;&#x4E2A;&#x5173;&#x7CFB;&#x5728;&#x67D0;&#x4E9B;&#x65F6;&#x5019;&#x5C06;&#x4E0D;&#x53EF;&#x907F;&#x514D;&#x7684;&#x5931;&#x8D25;&#x3002;</p>
<p><strong>&#x96EA;&#x5D29;&#x6548;&#x5E94;</strong>&#xFF1A;&#x591A;&#x4E2A;&#x5FAE;&#x670D;&#x52A1;&#x4E4B;&#x95F4;&#x8C03;&#x7528;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5047;&#x8BBE;&#x5FAE;&#x670D;&#x52A1;A&#x8C03;&#x7528;&#x5FAE;&#x670D;&#x52A1;B&#x548C;&#x5FAE;&#x670D;&#x52A1;C&#xFF0C;&#x5FAE;&#x670D;&#x52A1;B&#x548C;&#x5FAE;&#x670D;&#x52A1;C&#x53C8;&#x53BB;&#x8C03;&#x7528;&#x5176;&#x4ED6;&#x7684;&#x5FAE;&#x670D;&#x52A1;&#xFF0C;&#x8FD9;&#x5C31;&#x662F;&#x6240;&#x8C13;&#x7684;&quot;&#x6247;&#x51FA;&quot;&#x3002;&#x5982;&#x679C;&#x6247;&#x51FA;&#x7684;&#x94FE;&#x8DEF;&#x4E0A;&#x7684;&#x67D0;&#x4E2A;&#x5FAE;&#x670D;&#x52A1;&#x7684;&#x8C03;&#x7528;&#x54CD;&#x5E94;&#x65F6;&#x95F4;&#x8FC7;&#x957F;&#x6216;&#x8005;&#x4E0D;&#x53EF;&#x7528;&#xFF0C;&#x5BF9;&#x5FAE;&#x670D;&#x52A1;A&#x7684;&#x8C03;&#x7528;&#x5C31;&#x4F1A;&#x5360;&#x7528;&#x8D8A;&#x6765;&#x8D8A;&#x591A;&#x7684;&#x7CFB;&#x7EDF;&#x8D44;&#x6E90;&#xFF0C;&#x8FDB;&#x800C;&#x5F15;&#x8D77;&#x7CFB;&#x7EDF;&#x5D29;&#x6E83;&#xFF0C;&#x5C31;&#x662F;&#x6240;&#x8C13;&#x7684;<code>&quot;&#x96EA;&#x5D29;&#x6548;&#x5E94;&quot;</code>&#x3002;</p>
<p>&#x5BF9;&#x4E8E;&#x9AD8;&#x6D41;&#x91CF;&#x7684;&#x5E94;&#x7528;&#x6765;&#x8BF4;&#xFF0C;&#x5355;&#x4E00;&#x7684;&#x540E;&#x7AEF;&#x4F9D;&#x8D56;&#x53EF;&#x80FD;&#x5BFC;&#x81F4;&#x6240;&#x6709;&#x7684;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x7684;&#x6240;&#x6709;&#x8D44;&#x6E90;&#x90FD;&#x5728;&#x51E0;&#x79D2;&#x949F;&#x5185;&#x9971;&#x548C;&#x3002;&#x6BD4;&#x5931;&#x8D25;&#x66F4;&#x7CDF;&#x7CD5;&#x7684;&#x4E8B;&#xFF0C;&#x8FD9;&#x4E9B;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x8FD8;&#x53EF;&#x80FD;&#x5BFC;&#x81F4;&#x670D;&#x52A1;&#x4E4B;&#x95F4;&#x7684;&#x5EF6;&#x8FDF;&#x589E;&#x52A0;&#xFF0C;&#x5907;&#x4EFD;&#x961F;&#x5217;&#xFF0C;&#x7EBF;&#x7A0B;&#x548C;&#x5176;&#x4ED6;&#x8D44;&#x6E90;&#x7D27;&#x5F20;&#xFF0C;&#x5BFC;&#x81F4;&#x6574;&#x4E2A;&#x7CFB;&#x7EDF;&#x53D1;&#x751F;&#x66F4;&#x591A;&#x7684;&#x7EA7;&#x8054;&#x6545;&#x969C;&#x3002;&#x8FD9;&#x4E9B;&#x90FD;&#x8868;&#x793A;&#x9700;&#x8981;&#x5BF9;&#x6545;&#x969C;&#x548C;&#x5EF6;&#x8FDF;&#x8FDB;&#x884C;&#x9694;&#x79BB;&#x548C;&#x7BA1;&#x7406;&#xFF0C;&#x4EE5;&#x4FBF;&#x5355;&#x4E2A;&#x4F9D;&#x8D56;&#x5173;&#x7CFB;&#x7684;&#x5931;&#x8D25;&#xFF0C;&#x4E0D;&#x80FD;&#x53D6;&#x6D88;&#x6574;&#x4E2A;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x6216;&#x8005;&#x7CFB;&#x7EDF;&#x3002;</p>
<h3 id="2&#x4EC0;&#x4E48;&#x662F;hystrix&#xFF1F;"><a name="2&#x4EC0;&#x4E48;&#x662F;hystrix&#xFF1F;" class="plugin-anchor" href="#2&#x4EC0;&#x4E48;&#x662F;hystrix&#xFF1F;"><i class="fa fa-link" aria-hidden="true"></i></a>2.&#x4EC0;&#x4E48;&#x662F;Hystrix&#xFF1F;</h3>
<p>Hystrix &#x662F;&#x4E00;&#x4E2A;&#x7528;&#x4E8E;&#x5904;&#x7406;&#x5206;&#x5E03;&#x5F0F;&#x7CFB;&#x7EDF;&#x7684;&#x5EF6;&#x8FDF;&#x548C;&#x5BB9;&#x9519;&#x7684;&#x5F00;&#x6E90;&#x5E93;&#xFF0C;&#x5728;&#x5206;&#x5E03;&#x5F0F;&#x7CFB;&#x7EDF;&#x91CC;&#xFF0C;&#x8BB8;&#x591A;&#x4F9D;&#x8D56;&#x4E0D;&#x53EF;&#x907F;&#x514D;&#x7684;&#x4F1A;&#x8C03;&#x7528;&#x5931;&#x8D25;&#xFF0C;&#x6BD4;&#x5982;&#x8D85;&#x65F6;&#x3001;&#x5F02;&#x5E38;&#x7B49;&#x3002;Hystrix &#x80FD;&#x591F;&#x4FDD;&#x8BC1;&#x5728;&#x4E00;&#x4E2A;&#x4F9D;&#x8D56;&#x51FA;&#x95EE;&#x9898;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x4E0D;&#x4F1A;&#x5BFC;&#x81F4;&#x6574;&#x4E2A;&#x670D;&#x52A1;&#x5931;&#x8D25;&#xFF0C;&#x907F;&#x514D;&#x7EA7;&#x8054;&#x6545;&#x969C;&#xFF0C;&#x4EE5;&#x63D0;&#x9AD8;&#x5206;&#x5E03;&#x5F0F;&#x7CFB;&#x7EDF;&#x7684;&#x5F39;&#x6027;&#x3002;</p>
<p>&quot;&#x65AD;&#x8DEF;&#x5668;&quot;&#x672C;&#x8EAB;&#x662F;&#x4E00;&#x79CD;&#x88C5;&#x7F6E;&#xFF0C;&#x5F53;&#x67D0;&#x4E2A;&#x670D;&#x52A1;&#x5355;&#x5143;&#x53D1;&#x751F;&#x6545;&#x969C;&#x4E4B;&#x540E;&#xFF0C;&#x901A;&#x8FC7;&#x65AD;&#x8DEF;&#x5668;&#x7684;&#x6545;&#x969C;&#x76D1;&#x63A7;&#xFF08;&#x7C7B;&#x4F3C;&#x4E8E;&#x7194;&#x65AD;&#x4FDD;&#x9669;&#x4E1D;&#xFF09;&#xFF0C;&#x5411;&#x8C03;&#x7528;&#x65B9;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x7B26;&#x5408;&#x9884;&#x671F;&#x7684;&#x3001;&#x53EF;&#x5904;&#x7406;&#x7684;&#x5907;&#x9009;&#x54CD;&#x5E94;&#xFF08;FallBack&#xFF09;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x957F;&#x65F6;&#x95F4;&#x7684;&#x7B49;&#x5F85;&#x6216;&#x8005;&#x629B;&#x51FA;&#x8C03;&#x7528;&#x65B9;&#x65E0;&#x6CD5;&#x5904;&#x7406;&#x7684;&#x5F02;&#x5E38;&#xFF0C;&#x8FD9;&#x6837;&#x5C31;&#x4FDD;&#x8BC1;&#x4E86;&#x670D;&#x52A1;&#x8C03;&#x7528;&#x65B9;&#x7684;&#x7EBF;&#x7A0B;&#x4E0D;&#x4F1A;&#x88AB;&#x957F;&#x65F6;&#x95F4;&#x3001;&#x4E0D;&#x5FC5;&#x8981;&#x7684;&#x5360;&#x7528;&#xFF0C;&#x4ECE;&#x800C;&#x907F;&#x514D;&#x4E86;&#x6545;&#x969C;&#x5728;&#x5206;&#x5E03;&#x5F0F;&#x7CFB;&#x7EDF;&#x4E2D;&#x7684;&#x8513;&#x5EF6;&#xFF0C;&#x4E43;&#x81F3;&#x96EA;&#x5D29;&#x3002;</p>
<p><strong>&#x670D;&#x52A1;&#x7194;&#x65AD;</strong>&#xFF1A;&#x7194;&#x65AD;&#x673A;&#x5236;&#x662F;&#x5E94;&#x5BF9;&#x96EA;&#x5D29;&#x6548;&#x5E94;&#x7684;&#x4E00;&#x79CD;&#x5FAE;&#x670D;&#x52A1;&#x94FE;&#x8DEF;&#x4FDD;&#x62A4;&#x673A;&#x5236;&#x3002;</p>
<p>&#x5F53;&#x6247;&#x51FA;&#x94FE;&#x8DEF;&#x7684;&#x67D0;&#x4E2A;&#x5FAE;&#x670D;&#x52A1;&#x4E0D;&#x53EF;&#x7528;&#x6216;&#x8005;&#x54CD;&#x5E94;&#x65F6;&#x95F4;&#x592A;&#x957F;&#x65F6;&#xFF0C;&#x4F1A;&#x8FDB;&#x884C;&#x670D;&#x52A1;&#x964D;&#x7EA7;&#xFF0C;&#x8FDB;&#x800C;&#x7194;&#x65AD;&#x8BE5;&#x8282;&#x70B9;&#x5FAE;&#x670D;&#x52A1;&#x7684;&#x8C03;&#x7528;&#xFF0C;&#x5FEB;&#x901F;&#x8FD4;&#x56DE;&quot;&#x9519;&#x8BEF;&quot;&#x7684;&#x54CD;&#x5E94;&#x4FE1;&#x606F;&#x3002;&#x5F53;&#x68C0;&#x6D4B;&#x5230;&#x8BE5;&#x8282;&#x70B9;&#x5FAE;&#x670D;&#x52A1;&#x8C03;&#x7528;&#x54CD;&#x5E94;&#x6B63;&#x5E38;&#x540E;&#x6062;&#x590D;&#x8C03;&#x7528;&#x94FE;&#x8DEF;&#x3002;&#x5728;springcloud&#x6846;&#x67B6;&#x91CC;&#x7194;&#x65AD;&#x673A;&#x5236;&#x901A;&#x8FC7;Hystrix&#x5B9E;&#x73B0;&#x3002;Hystrix&#x4F1A;&#x76D1;&#x63A7;&#x5FAE;&#x670D;&#x52A1;&#x95F4;&#x8C03;&#x7528;&#x7684;&#x72B6;&#x51B5;&#xFF0C;&#x5F53;&#x5931;&#x8D25;&#x7684;&#x8C03;&#x7528;&#x5230;&#x4E00;&#x5B9A;&#x9608;&#x503C;&#xFF0C;&#x7F3A;&#x7701;&#x662F;5&#x79D2;&#x5185;20&#x6B21;&#x8C03;&#x7528;&#x5931;&#x8D25;&#x5C31;&#x4F1A;&#x542F;&#x52A8;&#x7194;&#x65AD;&#x673A;&#x5236;&#x3002;</p>
<h3 id="3hystrix-&#x7684;&#x529F;&#x80FD;"><a name="3hystrix-&#x7684;&#x529F;&#x80FD;" class="plugin-anchor" href="#3hystrix-&#x7684;&#x529F;&#x80FD;"><i class="fa fa-link" aria-hidden="true"></i></a>3.Hystrix &#x7684;&#x529F;&#x80FD;</h3>
<ul>
<li><p>&#x670D;&#x52A1;&#x964D;&#x7EA7;</p>
<p>&#x670D;&#x52A1;&#x5668;&#x7E41;&#x5FD9;&#xFF0C;&#x8BF7;&#x7A0D;&#x540E;&#x518D;&#x8BD5;&#xFF0C;&#x4E0D;&#x8BA9;&#x5BA2;&#x6237;&#x7AEF;&#x7B49;&#x5F85;&#x5E76;&#x7ACB;&#x523B;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x597D;&#x53CB;&#x63D0;&#x793A;&#x3002;</p>
<p>&#x54EA;&#x4E9B;&#x60C5;&#x51B5;&#x4F1A;&#x89E6;&#x53D1;&#x964D;&#x7EA7;&#xFF1A;&#x7A0B;&#x5E8F;&#x8FD0;&#x884C;&#x5F02;&#x5E38;&#x3001;&#x8D85;&#x65F6;&#x3001;&#x670D;&#x52A1;&#x7194;&#x65AD;&#x89E6;&#x53D1;&#x670D;&#x52A1;&#x964D;&#x7EA7;&#x548C;&#x7EBF;&#x7A0B;&#x6C60;/&#x4FE1;&#x53F7;&#x91CF;&#x6253;&#x6EE1;&#x4E5F;&#x4F1A;&#x5BFC;&#x81F4;&#x670D;&#x52A1;&#x964D;&#x7EA7;</p>
</li>
<li><p>&#x670D;&#x52A1;&#x7194;&#x65AD;</p>
<p>&#x7C7B;&#x6BD4;&#x4FDD;&#x9669;&#x4E1D;&#x8FBE;&#x5230;&#x6700;&#x5927;&#x670D;&#x52A1;&#x8BBF;&#x95EE;&#x540E;&#xFF0C;&#x76F4;&#x63A5;&#x62D2;&#x7EDD;&#x8BBF;&#x95EE;&#xFF0C;&#x62C9;&#x95F8;&#x9650;&#x7535;&#xFF0C;&#x7136;&#x540E;&#x8C03;&#x7528;&#x670D;&#x52A1;&#x964D;&#x7EA7;&#x7684;&#x65B9;&#x6CD5;&#x5E76;&#x8FD4;&#x56DE;&#x53CB;&#x597D;&#x63D0;&#x793A;</p>
</li>
</ul>
<ul>
<li><p>&#x670D;&#x52A1;&#x9650;&#x6D41;</p>
<p>&#x79D2;&#x6740;&#x9AD8;&#x5E76;&#x53D1;&#x7B49;&#x64CD;&#x4F5C;&#xFF0C;&#x4E25;&#x7981;&#x4E00;&#x7A9D;&#x8702;&#x7684;&#x8FC7;&#x6765;&#x62E5;&#x6324;&#xFF0C;&#x5927;&#x5BB6;&#x6392;&#x961F;&#xFF0C;&#x4E00;&#x79D2;&#x949F;N&#x4E2A;&#xFF0C;&#x6709;&#x5E8F;&#x8FDB;&#x884C;</p>
</li>
<li><p>&#x63A5;&#x8FD1;&#x5B9E;&#x65F6;&#x7684;&#x76D1;&#x63A7;</p>
</li>
<li><p>...</p>
</li>
</ul>
<h3 id="4-&#x5982;&#x4F55;&#x63A5;&#x5165;"><a name="4-&#x5982;&#x4F55;&#x63A5;&#x5165;" class="plugin-anchor" href="#4-&#x5982;&#x4F55;&#x63A5;&#x5165;"><i class="fa fa-link" aria-hidden="true"></i></a>4. &#x5982;&#x4F55;&#x63A5;&#x5165;</h3>
<p>&#x26A0;&#xFE0F; &#x4E00;&#x822C;&#x90FD;&#x662F;&#x5BA2;&#x6237;&#x7AEF;&#xFF08;&#x6D88;&#x8D39;&#x8005;&#xFF09;&#x53BB;&#x63A5;&#x5165;&#xFF0C;&#x4F46;&#x662F;&#x751F;&#x4EA7;&#x8005;&#x548C;&#x6D88;&#x8D39;&#x8005;&#x90FD;&#x53EF;&#x4EE5;&#x63A5;&#x5165;&#xFF0C;&#x63A5;&#x5165;&#x65B9;&#x5F0F;&#x4E5F;&#x662F;&#x4E00;&#x6837;&#x7684;&#xFF0C;&#x6B64;&#x5904;&#x5728;&#x6D88;&#x8D39;&#x8005;&#x7AEF;&#x8FDB;&#x884C;&#x63A5;&#x5165;&#x793A;&#x4F8B;&#x3002;</p>
<p>pom.xml</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">dependencies</span>&gt;</span>

        <span class="hljs-comment">&lt;!-- &#x2705;&#x65B0;&#x589E;hystrix--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.cloud<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-cloud-starter-netflix-hystrix<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
              <span class="hljs-comment">&lt;!--&#x2705; &#x4E0D;&#x52A0;&#x53EF;&#x80FD;&#x627E;&#x4E0D;&#x5230;@HystrixCommand--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.netflix.hystrix<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>hystrix-javanica<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>RELEASE<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

        <span class="hljs-comment">&lt;!-- OpenFeign &#x4F9D;&#x8D56; --&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.cloud<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-cloud-starter-openfeign<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.cloud<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-cloud-starter-netflix-eureka-client<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

        <span class="hljs-comment">&lt;!--web--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-web<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-actuator<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-devtools<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">scope</span>&gt;</span>runtime<span class="hljs-tag">&lt;/<span class="hljs-name">scope</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">optional</span>&gt;</span>true<span class="hljs-tag">&lt;/<span class="hljs-name">optional</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.projectlombok<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>lombok<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">optional</span>&gt;</span>true<span class="hljs-tag">&lt;/<span class="hljs-name">optional</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-test<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">scope</span>&gt;</span>test<span class="hljs-tag">&lt;/<span class="hljs-name">scope</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.*******.springcloud<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>api-common<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>${project.version}<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

    <span class="hljs-tag">&lt;/<span class="hljs-name">dependencies</span>&gt;</span>
</code></pre>
<p>Application.yml</p>
<pre><code class="lang-yml"><span class="hljs-comment"># &#x76EE;&#x524D;&#x6765;&#x8BF4;&#x6CA1;&#x6709;&#x53D8;&#x5316;</span>
<span class="hljs-attr">server:</span>
<span class="hljs-attr">  port:</span> <span class="hljs-number">80</span>


<span class="hljs-attr">eureka:</span>
<span class="hljs-attr">  client:</span>
<span class="hljs-attr">    register-with-eureka:</span> <span class="hljs-literal">true</span>
<span class="hljs-attr">    fetch-registry:</span> <span class="hljs-literal">true</span>
<span class="hljs-attr">    service-url:</span>
<span class="hljs-attr">      defaultZone:</span> http://localhost:<span class="hljs-number">7001</span>/eureka/
<span class="hljs-attr">spring:</span>
<span class="hljs-attr">  application:</span>
<span class="hljs-attr">    name:</span> eureka-consumer-order

<span class="hljs-comment"># &#x8BBE;&#x7F6E;feign &#x5BA2;&#x6237;&#x7AEF;&#x8D85;&#x65F6;&#x65F6;&#x95F4;(OpenFeign&#x9ED8;&#x8BA4;&#x652F;&#x6301;ribbon)</span>
<span class="hljs-attr">ribbon:</span>
  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x5EFA;&#x7ACB;&#x8FDE;&#x63A5;&#x540E;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x8BFB;&#x53D6;&#x5230;&#x53EF;&#x7528;&#x8D44;&#x6E90;&#x6240;&#x7528;&#x7684;&#x65F6;&#x95F4;</span>
<span class="hljs-attr">  ReadTimeout:</span> <span class="hljs-number">5000</span>
  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x5EFA;&#x7ACB;&#x8FDE;&#x63A5;&#x6240;&#x7528;&#x7684;&#x65F6;&#x95F4;,&#x9002;&#x7528;&#x4E8E;&#x7F51;&#x7EDC;&#x72B6;&#x51B5;&#x6B63;&#x5E38;&#x7684;&#x60C5;&#x51B5;&#x4E0B;,&#x4E24;&#x7AEF;&#x8FDE;&#x63A5;&#x6240;&#x7528;&#x7684;&#x65F6;&#x95F4;</span>
<span class="hljs-attr">  ConnectTimeout:</span> <span class="hljs-number">5000</span>

<span class="hljs-attr">logging:</span>
<span class="hljs-attr">  level:</span>
    <span class="hljs-comment"># feign &#x65E5;&#x5FD7;&#x4EE5;&#x4EC0;&#x4E48;&#x7EA7;&#x522B;&#x76D1;&#x63A7;&#x54EA;&#x4E2A;&#x63A5;&#x53E3;</span>
    com.****.springcloud.service.IRemotePaymentService: debug
</code></pre>
<p>&#x542F;&#x52A8;&#x7C7B;&#xFF0C;&#x65B0;&#x589E; @EnableCircuitBreaker &#x5F00;&#x542F;&#x7194;&#x65AD;</p>
<pre><code class="lang-java"><span class="hljs-meta">@SpringBootApplication</span>
<span class="hljs-meta">@EnableEurekaClient</span>
<span class="hljs-meta">@EnableFeignClients</span>
<span class="hljs-meta">@EnableCircuitBreaker</span>
<span class="hljs-meta">@EnableHystrix</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">OrderMainApplication</span></span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        SpringApplication.run(OrderMainApplication.class,args);
    }
}
</code></pre>
<p>&#x4E1A;&#x52A1;&#x7C7B;</p>
<pre><code class="lang-java"><span class="hljs-meta">@RestController</span>
<span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/order&quot;</span>)
<span class="hljs-meta">@Slf</span>4j
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">OrderController</span> </span>{

    <span class="hljs-meta">@Autowired</span>
    <span class="hljs-keyword">private</span> IRemotePaymentService remotePaymentService;

      <span class="hljs-comment">// &#x6CE8;&#x610F;pom &#x53EF;&#x80FD;&#x627E;&#x4E0D;&#x5230;@HystrixCommand</span>
    <span class="hljs-meta">@GetMapping</span>(<span class="hljs-string">&quot;/getPaymentById/{id}&quot;</span>)
    <span class="hljs-meta">@HystrixCommand</span>(fallbackMethod = <span class="hljs-string">&quot;testHystrixTimoutFallback&quot;</span>,commandProperties = {
            <span class="hljs-meta">@HystrixProperty</span>(name=<span class="hljs-string">&quot;execution.isolation.thread.timeoutInMilliseconds&quot;</span>,value=<span class="hljs-string">&quot;3000&quot;</span>)
    })
    <span class="hljs-function"><span class="hljs-keyword">public</span> CommonResult&lt;Payment&gt; <span class="hljs-title">get</span><span class="hljs-params">(@PathVariable(<span class="hljs-string">&quot;id&quot;</span>)</span> Long id)</span>{
        CommonResult&lt;Payment&gt; paymentById = remotePaymentService.getPayment(id);
        <span class="hljs-keyword">try</span>{
            TimeUnit.SECONDS.sleep(<span class="hljs-number">5</span>);
        }<span class="hljs-keyword">catch</span> (Exception e){
            System.out.println(<span class="hljs-string">&quot;&#x7761;&#x89C9;&#x6709;&#x95EE;&#x9898;&quot;</span>);
        }
        <span class="hljs-keyword">return</span> paymentById;
    }


    <span class="hljs-comment">// &#x515C;&#x5E95;&#x65B9;&#x6CD5;&#xFF01;</span>
    <span class="hljs-comment">// &#x8E29;&#x5751;&#x4E86;&#xFF0C;&#x6211;&#x7684;&#x515C;&#x5E95;&#x65B9;&#x6CD5;&#x5199;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x662F;String&#xFF0C;&#x7136;&#x540E;&#x8BBF;&#x95EE;&#x5C31;&#x4F1A;&#x62A5;&#x9519;&#xFF0C;&#x6240;&#x4EE5;&#x515C;&#x5E95;&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x503C;&#x5FC5;&#x987B;&#x548C;&#x539F;&#x65B9;&#x6CD5;&#x4E00;&#x81F4;&#x3002;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> CommonResult&lt;Payment&gt; <span class="hljs-title">testHystrixTimoutFallback</span><span class="hljs-params">(Long id)</span> <span class="hljs-keyword">throws</span> InterruptedException </span>{
         log.info(id + <span class="hljs-string">&quot;&#x964D;&#x7EA7;&#x670D;&#x52A1;&#x65B9;&#x6CD5;&#x6267;&#x884C;!&quot;</span>);
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>;
    }
}
</code></pre>
<h3 id="5&#x6BCF;&#x4E2A;&#x65B9;&#x6CD5;&#x4E00;&#x4E2A;&#x515C;&#x5E95;&#x65B9;&#x6CD5;&#xFF1F;&#x5982;&#x4F55;&#x89E3;&#x51B3;&#xFF1F;defaultprotitiesdefaultfallback-&#x65B9;&#x6CD5;&#x540D;"><a name="5&#x6BCF;&#x4E2A;&#x65B9;&#x6CD5;&#x4E00;&#x4E2A;&#x515C;&#x5E95;&#x65B9;&#x6CD5;&#xFF1F;&#x5982;&#x4F55;&#x89E3;&#x51B3;&#xFF1F;defaultprotitiesdefaultfallback-&#x65B9;&#x6CD5;&#x540D;" class="plugin-anchor" href="#5&#x6BCF;&#x4E2A;&#x65B9;&#x6CD5;&#x4E00;&#x4E2A;&#x515C;&#x5E95;&#x65B9;&#x6CD5;&#xFF1F;&#x5982;&#x4F55;&#x89E3;&#x51B3;&#xFF1F;defaultprotitiesdefaultfallback-&#x65B9;&#x6CD5;&#x540D;"><i class="fa fa-link" aria-hidden="true"></i></a>5.&#x6BCF;&#x4E2A;&#x65B9;&#x6CD5;&#x4E00;&#x4E2A;&#x515C;&#x5E95;&#x65B9;&#x6CD5;&#xFF1F;&#x5982;&#x4F55;&#x89E3;&#x51B3;&#xFF1F;@DefaultProtities(defaultFallback= &quot;&#x65B9;&#x6CD5;&#x540D;&quot;)</h3>
<p>&#x4E0A;&#x9762;&#x7684;&#x5BF9;&#x63A5;&#x65B9;&#x5F0F;&#xFF0C;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#x4E00;&#x4E2A;&#x515C;&#x5E95;&#xFF0C;&#x4EE3;&#x7801;&#x8FC7;&#x5EA6;&#x5197;&#x4F59;&#xFF0C;&#x6240;&#x4EE5;&#x9700;&#x8981;&#x4E00;&#x4E2A;&#x5168;&#x5C40;&#x670D;&#x52A1;&#x964D;&#x7EA7;&#x3002;</p>
<p>&#x5C31;&#x8FD1;&#x539F;&#x5219;&#xFF0C;&#x72EC;&#x7279;&#x7684;&#x4E1A;&#x52A1;&#xFF0C;&#x9700;&#x8981;&#x7279;&#x5B9A;&#x7684;&#x964D;&#x7EA7;&#x65B9;&#x6CD5;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5355;&#x72EC;&#x7528;&#x4E0A;&#x8FF0;&#x65B9;&#x6CD5;&#x5904;&#x7406;&#xFF0C;&#x5176;&#x4ED6;&#x666E;&#x901A;&#x65B9;&#x6CD5;&#x7528;&#x7EDF;&#x4E00;&#x7684;&#x964D;&#x7EA7;&#x65B9;&#x5F0F;&#x3002;</p>
<p>&#x5F53;&#x7136;&#x65B9;&#x6CD5;&#x4E0A;&#x90FD;&#x9700;&#x8981;&#x8D34;@HystrixCommand &#x6CE8;&#x89E3;&#xFF0C;&#x5426;&#x5219;&#x5C31;&#x662F;&#x8BF4;&#x6211;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x4E0D;&#x9700;&#x8981;&#x964D;&#x7EA7;&#x4E86;&#x3002;</p>
<pre><code class="lang-java"><span class="hljs-meta">@RestController</span>
<span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/order&quot;</span>)
<span class="hljs-meta">@Slf</span>4j
<span class="hljs-meta">@DefaultProperties</span>(defaultFallback = <span class="hljs-string">&quot;testHystrixGlobalFallback&quot;</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">OrderController</span> </span>{

    <span class="hljs-meta">@Autowired</span>
    <span class="hljs-keyword">private</span> IRemotePaymentService remotePaymentService;

    <span class="hljs-meta">@GetMapping</span>(<span class="hljs-string">&quot;/getPaymentById/{id}&quot;</span>)
    <span class="hljs-meta">@HystrixCommand</span>(fallbackMethod = <span class="hljs-string">&quot;testHystrixTimoutFallback&quot;</span>,commandProperties = {
            <span class="hljs-meta">@HystrixProperty</span>(name=<span class="hljs-string">&quot;execution.isolation.thread.timeoutInMilliseconds&quot;</span>,value=<span class="hljs-string">&quot;3000&quot;</span>)
    })
    <span class="hljs-function"><span class="hljs-keyword">public</span> CommonResult&lt;Payment&gt; <span class="hljs-title">get</span><span class="hljs-params">(@PathVariable(<span class="hljs-string">&quot;id&quot;</span>)</span> Long id)</span>{
        CommonResult&lt;Payment&gt; paymentById = remotePaymentService.getPayment(id);
        <span class="hljs-keyword">try</span>{
            TimeUnit.SECONDS.sleep(<span class="hljs-number">5</span>);
        }<span class="hljs-keyword">catch</span> (Exception e){
            System.out.println(<span class="hljs-string">&quot;&#x7761;&#x89C9;&#x6709;&#x95EE;&#x9898;&quot;</span>);
        }
        <span class="hljs-keyword">return</span> paymentById;
    }

      <span class="hljs-comment">// &#x5355;&#x4E2A;&#x515C;&#x5E95;&#x65B9;&#x6CD5;&#xFF01;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> CommonResult&lt;Payment&gt; <span class="hljs-title">testHystrixTimoutFallback</span><span class="hljs-params">(Long id)</span> <span class="hljs-keyword">throws</span> InterruptedException </span>{
         log.info(id + <span class="hljs-string">&quot;&#x964D;&#x7EA7;&#x670D;&#x52A1;&#x65B9;&#x6CD5;&#x6267;&#x884C;!&quot;</span>);
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>;
    }


    <span class="hljs-meta">@GetMapping</span>(<span class="hljs-string">&quot;/getString&quot;</span>)
    <span class="hljs-meta">@HystrixCommand</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">get</span><span class="hljs-params">()</span></span>{
        <span class="hljs-keyword">int</span> i = <span class="hljs-number">1</span>/<span class="hljs-number">0</span>;
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;&quot;</span>;
    }

    <span class="hljs-comment">// &#x5168;&#x5C40;&#x515C;&#x5E95;&#x65B9;&#x6CD5;&#xFF01;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">testHystrixGlobalFallback</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> InterruptedException </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;&#x5168;&#x5C40;&#x7684;&#x964D;&#x7EA7;&#x670D;&#x52A1;&#x65B9;&#x6CD5;&#x6267;&#x884C;!&quot;</span>;

    }
}
</code></pre>
<h3 id="6&#x548C;&#x4E1A;&#x52A1;&#x4EE3;&#x7801;&#x7CC5;&#x5728;&#x4E00;&#x5757;&#x513F;&#xFF1F;&#x5982;&#x4F55;&#x89E3;&#x51B3;&#xFF1F;feignclientvalue--&#x670D;&#x52A1;fallback--class"><a name="6&#x548C;&#x4E1A;&#x52A1;&#x4EE3;&#x7801;&#x7CC5;&#x5728;&#x4E00;&#x5757;&#x513F;&#xFF1F;&#x5982;&#x4F55;&#x89E3;&#x51B3;&#xFF1F;feignclientvalue--&#x670D;&#x52A1;fallback--class" class="plugin-anchor" href="#6&#x548C;&#x4E1A;&#x52A1;&#x4EE3;&#x7801;&#x7CC5;&#x5728;&#x4E00;&#x5757;&#x513F;&#xFF1F;&#x5982;&#x4F55;&#x89E3;&#x51B3;&#xFF1F;feignclientvalue--&#x670D;&#x52A1;fallback--class"><i class="fa fa-link" aria-hidden="true"></i></a>6.&#x548C;&#x4E1A;&#x52A1;&#x4EE3;&#x7801;&#x7CC5;&#x5728;&#x4E00;&#x5757;&#x513F;&#xFF1F;&#x5982;&#x4F55;&#x89E3;&#x51B3;&#xFF1F;@FeignClient(value = &quot;&#x670D;&#x52A1;&quot;,fallback = *.class)</h3>
<pre><code class="lang-java"><span class="hljs-comment">//&#x4FEE;&#x6539;----&#x63A5;&#x53E3;</span>
<span class="hljs-meta">@Component</span> <span class="hljs-comment">//&#x522B;&#x5FD8;</span>
<span class="hljs-meta">@FeignClient</span>(value = <span class="hljs-string">&quot;eureka-provider-payment&quot;</span>,fallback = RemotePaymentFallbackServiceImpl.class)<span class="hljs-comment">//&#x58F0;&#x660E;&#x670D;&#x52A1;</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">IRemotePaymentService</span> </span>{

    <span class="hljs-meta">@GetMapping</span>(<span class="hljs-string">&quot;/payment/getPaymentById/{id}&quot;</span>)
    <span class="hljs-function">CommonResult&lt;Payment&gt; <span class="hljs-title">getPayment</span><span class="hljs-params">(@PathVariable(<span class="hljs-string">&quot;id&quot;</span>)</span> Long id)</span>;
}



<span class="hljs-comment">//&#x65B0;&#x589E;-----&#x4E00;&#x4E2A;&#x5B9E;&#x73B0;&#x7C7B;</span>
<span class="hljs-meta">@Component</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">RemotePaymentFallbackServiceImpl</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">IRemotePaymentService</span> </span>{

    <span class="hljs-meta">@Override</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> CommonResult&lt;Payment&gt; <span class="hljs-title">getPayment</span><span class="hljs-params">(Long id)</span> </span>{
        CommonResult&lt;Payment&gt; objectCommonResult = <span class="hljs-keyword">new</span> CommonResult&lt;&gt;();
        objectCommonResult.setCode(<span class="hljs-number">500</span>);
        objectCommonResult.setMsg(<span class="hljs-string">&quot;&#x5BF9;&#x65B9;&#x670D;&#x52A1;&#x5668;&#x5B95;&#x673A;&#x4E86;&#xFF01;&#xFF01;&#xFF01;&#xFF01;&quot;</span>);
        objectCommonResult.setData(<span class="hljs-keyword">null</span>);
        <span class="hljs-keyword">return</span> objectCommonResult;
    }
}


<span class="hljs-comment">//&#x4FEE;&#x6539;-----&#x539F;&#x6765;&#x7684;controller</span>

<span class="hljs-meta">@RestController</span>
<span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/order&quot;</span>)
<span class="hljs-meta">@Slf</span>4j
<span class="hljs-meta">@DefaultProperties</span>(defaultFallback = <span class="hljs-string">&quot;testHystrixGlobalFallback&quot;</span>) <span class="hljs-comment">//&#x8FD9;&#x4E2A;&#x770B;&#x4E1A;&#x52A1;&#x60C5;&#x51B5;&#x5E72;&#x6389;</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">OrderController</span> </span>{

    <span class="hljs-meta">@Autowired</span>
    <span class="hljs-keyword">private</span> IRemotePaymentService remotePaymentService;

    <span class="hljs-meta">@GetMapping</span>(<span class="hljs-string">&quot;/getPaymentById/{id}&quot;</span>)
<span class="hljs-comment">//    @HystrixCommand(fallbackMethod = &quot;testHystrixTimoutFallback&quot;,commandProperties = {</span>
<span class="hljs-comment">//            @HystrixProperty(name=&quot;execution.isolation.thread.timeoutInMilliseconds&quot;,value=&quot;3000&quot;)</span>
<span class="hljs-comment">//    }) &#x8FD9;&#x4E2A;&#x6CE8;&#x89E3;&#x53EF;&#x4EE5;&#x5E72;&#x6389;&#x4E86;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> CommonResult&lt;Payment&gt; <span class="hljs-title">get</span><span class="hljs-params">(@PathVariable(<span class="hljs-string">&quot;id&quot;</span>)</span> Long id)</span>{
        CommonResult&lt;Payment&gt; paymentById = remotePaymentService.getPayment(id);
        <span class="hljs-keyword">try</span>{
            TimeUnit.SECONDS.sleep(<span class="hljs-number">5</span>);
        }<span class="hljs-keyword">catch</span> (Exception e){
            System.out.println(<span class="hljs-string">&quot;&#x7761;&#x89C9;&#x6709;&#x95EE;&#x9898;&quot;</span>);
        }
        <span class="hljs-keyword">return</span> paymentById;
    }


    <span class="hljs-meta">@GetMapping</span>(<span class="hljs-string">&quot;/getString&quot;</span>)
    <span class="hljs-meta">@HystrixCommand</span> <span class="hljs-comment">//&#x5F53;&#x7136;&#x65B9;&#x6CD5;&#x4E0A;&#x90FD;&#x9700;&#x8981;&#x8D34;@HystrixCommand &#x6CE8;&#x89E3;&#xFF0C;&#x5426;&#x5219;&#x5C31;&#x662F;&#x8BF4;&#x6211;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x4E0D;&#x9700;&#x8981;&#x964D;&#x7EA7;&#x4E86;&#x3002;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">get</span><span class="hljs-params">()</span></span>{
        <span class="hljs-keyword">int</span> i = <span class="hljs-number">1</span>/<span class="hljs-number">0</span>;
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;&quot;</span>;
    }

    <span class="hljs-comment">// &#x515C;&#x5E95;&#x65B9;&#x6CD5;&#xFF01;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> CommonResult&lt;Payment&gt; <span class="hljs-title">testHystrixTimoutFallback</span><span class="hljs-params">(Long id)</span> <span class="hljs-keyword">throws</span> InterruptedException </span>{
         log.info(id + <span class="hljs-string">&quot;&#x964D;&#x7EA7;&#x670D;&#x52A1;&#x65B9;&#x6CD5;&#x6267;&#x884C;!&quot;</span>);
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>;
    }

    <span class="hljs-comment">// &#x5168;&#x5C40;&#x515C;&#x5E95;&#x65B9;&#x6CD5;&#xFF01;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">testHystrixGlobalFallback</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> InterruptedException </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;&#x5168;&#x5C40;&#x7684;&#x964D;&#x7EA7;&#x670D;&#x52A1;&#x65B9;&#x6CD5;&#x6267;&#x884C;!&quot;</span>;

    }
}
</code></pre>
<p>Application.yml &#x8981;&#x6CE8;&#x610F;&#xFF1A;</p>
<pre><code class="lang-yml"><span class="hljs-comment"># &#x5F00;&#x542F;feign&#x8C03;&#x7528;</span>
<span class="hljs-attr">feign:</span>
<span class="hljs-attr">  hystrix:</span>
<span class="hljs-attr">    enabled:</span> <span class="hljs-literal">true</span>
<span class="hljs-comment"># &#x89E3;&#x8026;&#x964D;&#x7EA7;&#x7684;&#x8D85;&#x65F6;&#x65F6;&#x95F4;&#x914D;&#x7F6E;</span>
<span class="hljs-attr">hystrix:</span>
<span class="hljs-attr">  command:</span>
<span class="hljs-attr">    default:</span>
<span class="hljs-attr">      execution:</span>
<span class="hljs-attr">        isolation:</span>
<span class="hljs-attr">          thread:</span>
<span class="hljs-attr">            timeoutInMilliseconds:</span> <span class="hljs-number">3000</span>
</code></pre>
<h3 id="7&#x6CE8;&#x610F;&#x4E0A;&#x9762;&#x7684;&#x8BF4;&#x7684;&#x90FD;&#x662F;&#x964D;&#x7EA7;&#xFF0C;&#x7194;&#x65AD;&#x662F;&#x4EC0;&#x4E48;&#x5462;&#xFF1F;"><a name="7&#x6CE8;&#x610F;&#x4E0A;&#x9762;&#x7684;&#x8BF4;&#x7684;&#x90FD;&#x662F;&#x964D;&#x7EA7;&#xFF0C;&#x7194;&#x65AD;&#x662F;&#x4EC0;&#x4E48;&#x5462;&#xFF1F;" class="plugin-anchor" href="#7&#x6CE8;&#x610F;&#x4E0A;&#x9762;&#x7684;&#x8BF4;&#x7684;&#x90FD;&#x662F;&#x964D;&#x7EA7;&#xFF0C;&#x7194;&#x65AD;&#x662F;&#x4EC0;&#x4E48;&#x5462;&#xFF1F;"><i class="fa fa-link" aria-hidden="true"></i></a>7.&#x6CE8;&#x610F;&#x4E0A;&#x9762;&#x7684;&#x8BF4;&#x7684;&#x90FD;&#x662F;&#x964D;&#x7EA7;&#xFF0C;&#x7194;&#x65AD;&#x662F;&#x4EC0;&#x4E48;&#x5462;&#xFF1F;</h3>
<p>&#x7194;&#x65AD;&#x4E0E;&#x964D;&#x7EA7;&#x4E0D;&#x540C;&#x7684;&#x662F;&#xFF0C;&#x7194;&#x65AD;&#x5177;&#x6709;&#x5F53;&#x68C0;&#x6D4B;&#x5230;&#x8C03;&#x7528;&#x6B63;&#x5E38;&#x4EE5;&#x540E;&#xFF0C;&#x6062;&#x590D;&#x8C03;&#x7528;&#x94FE;&#x8DEF;&#x7684;&#x529F;&#x80FD;&#x3002;</p>
<p>&#x751F;&#x6D3B;&#x4E2D;&#x4E3E;&#x4F8B;&#x5C31;&#x662F;&#x5BB6;&#x91CC;&#x7535;&#x5668;&#x5F00;&#x592A;&#x591A;&#xFF0C;&#x7535;&#x538B;&#x8FC7;&#x9AD8;&#x5BFC;&#x81F4;&#x8DF3;&#x95F8;&#xFF0C;&#x5173;&#x6389;&#x51E0;&#x4E2A;&#x9AD8;&#x529F;&#x7387;&#x7684;&#x7535;&#x5668;&#x540E;&#x91CD;&#x65B0;&#x5408;&#x4E0A;&#x95F8;&#xFF0C;&#x5C31;&#x76F8;&#x5F53;&#x4E8E;&#x201C;&#x7194;&#x65AD;&#x201D;&#x7684;&#x529F;&#x80FD;&#x3002;</p>
<p><a href="https://martinfowler.com/bliki/CircuitBreaker.html" target="_blank">&#x9A6C;&#x4E01;&#x5F17;&#x52D2;&#x5BF9;&#x7194;&#x65AD;&#x7684;&#x7406;&#x89E3;</a>&#xFF0C;&#x5176;&#x4E2D;&#x4E00;&#x4E2A;&#x6BD4;&#x8F83;&#x91CD;&#x8981;&#x7684;&#x67B6;&#x6784;&#x56FE;&#xFF0C;&#x5982;&#x4E0B;&#x6240;&#x793A;&#xFF1A;</p>
<p><img src="https://tva1.sinaimg.cn/large/e6c9d24ely1h2ylof4vd7j20p40mwaar.jpg" alt="&#x7194;&#x65AD;&#x67B6;&#x6784;&#x56FE;"></p>
<p>&#x7B80;&#x8981;&#x89E3;&#x8BF4;&#x4E0A;&#x56FE;&#xFF1A;&#x9A6C;&#x4E01;&#x798F;&#x52D2;&#x7ED9;&#x8DF3;&#x95F8;(open) &#x5408;&#x95F8;&#xFF08;close&#xFF09;&#x589E;&#x52A0;&#x4E86;&#x4E00;&#x4E2A;&#x4E2D;&#x95F4;&#x6001;&#xFF08;Half open&#xFF09;&#xFF0C;&#x5F53;&#x8BBE;&#x5B9A;10s&#x5185;&#x8BBF;&#x95EE;&#x4E0A;&#x9650;&#x4E3A;100&#x4E2A;&#x8BF7;&#x6C42;&#xFF0C;&#x800C;&#x67D0;&#x4E2A;&#x65F6;&#x95F4;&#x8D85;&#x8FC7;&#x4E86;&#x8FD9;&#x4E2A;&#x4E0A;&#x9650;&#xFF0C;&#x5C31;&#x4F1A;&#x8F6C;&#x4E3A;open&#x6001;&#xFF0C;&#x5F53;&#x4E00;&#x6BB5;&#x65F6;&#x95F4;&#x540E;&#xFF0C;&#x6253;&#x5F00;Half Ope&#x72B6;&#x6001;&#x5C1D;&#x8BD5;&#x63A5;&#x53D7;&#x8BF7;&#x6C42;&#xFF0C;&#x5C1D;&#x8BD5;&#x6210;&#x529F;&#x540E;&#x8F6C;&#x4E3A;closed&#x72B6;&#x6001;&#xFF0C;&#x6B63;&#x5E38;&#x63A5;&#x53D7;&#x8BF7;&#x6C42;&#x3002;</p>
<h3 id="8&#x63A5;&#x5165;&#x7194;&#x65AD;"><a name="8&#x63A5;&#x5165;&#x7194;&#x65AD;" class="plugin-anchor" href="#8&#x63A5;&#x5165;&#x7194;&#x65AD;"><i class="fa fa-link" aria-hidden="true"></i></a>8.&#x63A5;&#x5165;&#x7194;&#x65AD;</h3>
<p>&#x7194;&#x65AD;&#x7684;&#x6548;&#x679C;&#xFF1A;&#x6211;&#x4EEC;&#x6D4B;&#x8BD5;&#x8F93;&#x5165;id=-31&#x72C2;&#x70B9;&#x5237;&#x65B0;&#x8FDB;&#x884C;&#x8C03;&#x7528;&#xFF0C;&#x8FD4;&#x56DE;&#x7684;&#x662F; <code>id &#x4E0D;&#x80FD;&#x4E3A;&#x8D1F;&#x6570;&#xFF0C;&#x8BF7;&#x7A0D;&#x540E;&#x518D;&#x8BD5; =&gt; -31</code> &#x3002;</p>
<p>&#x7136;&#x540E;&#x7ACB;&#x9A6C;&#x6362;&#x6210; id=11&#x70B9;&#x51FB;&#x8C03;&#x7528;&#xFF0C;&#x8FD4;&#x56DE;&#x7684;&#x4ECD;&#x7136;&#x662F; &#x9519;&#x8BEF;&#x4FE1;&#x606F;<code>id &#x4E0D;&#x80FD;&#x4E3A;&#x8D1F;&#x6570;&#xFF0C;&#x8BF7;&#x7A0D;&#x540E;&#x518D;&#x8BD5; =&gt; 11</code>&#xFF0C;11&#x660E;&#x660E;&#x4E0D;&#x662F;&#x8D1F;&#x6570;&#x554A;&#xFF0C;&#x56E0;&#x4E3A;&#x6B64;&#x65F6;&#x63A5;&#x53E3;&#x5DF2;&#x7ECF;&#x7194;&#x65AD;&#x3002;</p>
<p>&#x5F53;&#x6211;&#x518D;&#x591A;&#x6B21;&#x70B9;&#x51FB;&#x5237;&#x65B0;&#x8C03;&#x7528;id=11&#xFF0C;&#x5C31;&#x4F1A;&#x53D1;&#x73B0;&#x51E0;&#x6B21;&#x540E;&#x6062;&#x590D;&#x4E86;&#x6B63;&#x5E38;&#xFF0C;&#x6B64;&#x65F6;&#x5DF2;&#x7ECF;&#x53C8;half open&#x8F6C;&#x4E3A; open&#x3002;</p>
<pre><code class="lang-java">        <span class="hljs-comment">//&#x7194;&#x65AD;</span>
    <span class="hljs-meta">@GetMapping</span>(<span class="hljs-string">&quot;/circuit/getPaymentById/{id}&quot;</span>)
    <span class="hljs-meta">@HystrixCommand</span>(fallbackMethod = <span class="hljs-string">&quot;circuitBreakerFallback&quot;</span>,commandProperties = {
            <span class="hljs-meta">@HystrixProperty</span>(name = <span class="hljs-string">&quot;circuitBreaker.enabled&quot;</span>,value = <span class="hljs-string">&quot;true&quot;</span>),
            <span class="hljs-meta">@HystrixProperty</span>(name = <span class="hljs-string">&quot;circuitBreaker.requestVolumeThreshold&quot;</span>,value = <span class="hljs-string">&quot;10&quot;</span>),<span class="hljs-comment">//&#x8BF7;&#x6C42;&#x6B21;&#x6570;</span>
            <span class="hljs-meta">@HystrixProperty</span>(name = <span class="hljs-string">&quot;circuitBreaker.sleepWindowInMilliseconds&quot;</span>,value = <span class="hljs-string">&quot;10000&quot;</span>),<span class="hljs-comment">//&#x65F6;&#x95F4;&#x7A97;&#x53E3;&#x671F;</span>
            <span class="hljs-meta">@HystrixProperty</span>(name = <span class="hljs-string">&quot;circuitBreaker.errorThresholdPercentage&quot;</span>,value = <span class="hljs-string">&quot;60&quot;</span>)<span class="hljs-comment">//&#x5931;&#x8D25;&#x767E;&#x5206;&#x6BD4;</span>
    })
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getCircuitBreaker</span><span class="hljs-params">(@PathVariable(<span class="hljs-string">&quot;id&quot;</span>)</span> Long id) <span class="hljs-keyword">throws</span> Exception</span>{

        <span class="hljs-keyword">if</span>(id&lt;<span class="hljs-number">0</span>){
            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> Exception(<span class="hljs-string">&quot;id&#x4E0D;&#x80FD;&#x4E3A;&#x8D1F;&#x6570;!&quot;</span>);
        }
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;&#x8C03;&#x7528;&#x6210;&#x529F;&#x6D41;&#x6C34;&#x53F7;&quot;</span>+ IdUtil.simpleUUID();
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">circuitBreakerFallback</span><span class="hljs-params">(@PathVariable(<span class="hljs-string">&quot;id&quot;</span>)</span> Long id)</span>{

        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;id &#x4E0D;&#x80FD;&#x4E3A;&#x8D1F;&#x6570;&#xFF0C;&#x8BF7;&#x7A0D;&#x540E;&#x518D;&#x8BD5; =&gt; &quot;</span>+id;
    }
</code></pre>
<h3 id="9&#x603B;&#x7ED3;"><a name="9&#x603B;&#x7ED3;" class="plugin-anchor" href="#9&#x603B;&#x7ED3;"><i class="fa fa-link" aria-hidden="true"></i></a>9.&#x603B;&#x7ED3;</h3>
<p><strong>&#x670D;&#x52A1;&#x7194;&#x65AD;&#xFF1A;</strong>&#x5F53;Hystrix Command&#x8BF7;&#x6C42;&#x540E;&#x7AEF;&#x670D;&#x52A1;&#x5931;&#x8D25;&#x6570;&#x91CF;&#x8D85;&#x8FC7;&#x4E00;&#x5B9A;&#x6BD4;&#x4F8B;(&#x9ED8;&#x8BA4;50%), &#x65AD;&#x8DEF;&#x5668;&#x4F1A;&#x5207;&#x6362;&#x5230;&#x5F00;&#x8DEF;&#x72B6;&#x6001;(Open). &#x8FD9;&#x65F6;&#x6240;&#x6709;&#x8BF7;&#x6C42;&#x4F1A;&#x76F4;&#x63A5;&#x5931;&#x8D25;&#x800C;&#x4E0D;&#x4F1A;&#x53D1;&#x9001;&#x5230;&#x540E;&#x7AEF;&#x670D;&#x52A1;. &#x65AD;&#x8DEF;&#x5668;&#x4FDD;&#x6301;&#x5728;&#x5F00;&#x8DEF;&#x72B6;&#x6001;&#x4E00;&#x6BB5;&#x65F6;&#x95F4;&#x540E;(&#x9ED8;&#x8BA4;5&#x79D2;), &#x81EA;&#x52A8;&#x5207;&#x6362;&#x5230;&#x534A;&#x5F00;&#x8DEF;&#x72B6;&#x6001;(HALF-OPEN).&#x8FD9;&#x65F6;&#x4F1A;&#x5224;&#x65AD;&#x4E0B;&#x4E00;&#x6B21;&#x8BF7;&#x6C42;&#x7684;&#x8FD4;&#x56DE;&#x60C5;&#x51B5;, &#x5982;&#x679C;&#x8BF7;&#x6C42;&#x6210;&#x529F;, &#x65AD;&#x8DEF;&#x5668;&#x5207;&#x56DE;&#x95ED;&#x8DEF;&#x72B6;&#x6001;(CLOSED), &#x5426;&#x5219;&#x91CD;&#x65B0;&#x5207;&#x6362;&#x5230;&#x5F00;&#x8DEF;&#x72B6;&#x6001;(OPEN). Hystrix&#x7684;&#x65AD;&#x8DEF;&#x5668;&#x5C31;&#x50CF;&#x6211;&#x4EEC;&#x5BB6;&#x5EAD;&#x7535;&#x8DEF;&#x4E2D;&#x7684;&#x4FDD;&#x9669;&#x4E1D;, &#x4E00;&#x65E6;&#x540E;&#x7AEF;&#x670D;&#x52A1;&#x4E0D;&#x53EF;&#x7528;, &#x65AD;&#x8DEF;&#x5668;&#x4F1A;&#x76F4;&#x63A5;&#x5207;&#x65AD;&#x8BF7;&#x6C42;&#x94FE;, &#x907F;&#x514D;&#x53D1;&#x9001;&#x5927;&#x91CF;&#x65E0;&#x6548;&#x8BF7;&#x6C42;&#x5F71;&#x54CD;&#x7CFB;&#x7EDF;&#x541E;&#x5410;&#x91CF;, &#x5E76;&#x4E14;&#x65AD;&#x8DEF;&#x5668;&#x6709;&#x81EA;&#x6211;&#x68C0;&#x6D4B;&#x5E76;&#x6062;&#x590D;&#x7684;&#x80FD;&#x529B;.</p>
<p><strong>&#x670D;&#x52A1;&#x964D;&#x7EA7;&#xFF1A;</strong>Fallback&#x76F8;&#x5F53;&#x4E8E;&#x662F;&#x964D;&#x7EA7;&#x64CD;&#x4F5C;. &#x5BF9;&#x4E8E;&#x67E5;&#x8BE2;&#x64CD;&#x4F5C;, &#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;fallback&#x65B9;&#x6CD5;, &#x5F53;&#x8BF7;&#x6C42;&#x540E;&#x7AEF;&#x670D;&#x52A1;&#x51FA;&#x73B0;&#x5F02;&#x5E38;&#x7684;&#x65F6;&#x5019;, &#x53EF;&#x4EE5;&#x4F7F;&#x7528;fallback&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x7684;&#x503C;. fallback&#x65B9;&#x6CD5;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x4E00;&#x822C;&#x662F;&#x8BBE;&#x7F6E;&#x7684;&#x9ED8;&#x8BA4;&#x503C;&#x6216;&#x8005;&#x6765;&#x81EA;&#x7F13;&#x5B58;.&#x544A;&#x77E5;&#x540E;&#x9762;&#x7684;&#x8BF7;&#x6C42;&#x670D;&#x52A1;&#x4E0D;&#x53EF;&#x7528;&#x4E86;&#xFF0C;&#x4E0D;&#x8981;&#x518D;&#x6765;&#x4E86;&#x3002;</p>
<blockquote>
<p>&#x5355;&#x51FB;&#x56FE;&#x7247;&#x5C31;&#x53EF;&#x4EE5;&#x770B;&#x6E05;&#x4E86;</p>
</blockquote>
<p><img src="https://tva1.sinaimg.cn/large/e6c9d24ely1h3w5n6ttpaj212a0i9jup.jpg" alt=""></p>
<p><strong>Hystrix &#x8C03;&#x7528;&#x8FC7;&#x7A0B;&#xFF1A;</strong></p>
<ol>
<li><p>&#x6BCF;&#x6B21;&#x8C03;&#x7528;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x7684;HystrixCommand,&#x628A;&#x4F9D;&#x8D56;&#x8C03;&#x7528;&#x5C01;&#x88C5;&#x5728;run()&#x65B9;&#x6CD5;&#x4E2D;.</p>
</li>
<li><p>&#x6267;&#x884C;execute()/queue&#x505A;&#x540C;&#x6B65;&#x6216;&#x5F02;&#x6B65;&#x8C03;&#x7528;.</p>
</li>
<li><p>&#x5224;&#x65AD;&#x7194;&#x65AD;&#x5668;(circuit-breaker)&#x662F;&#x5426;&#x6253;&#x5F00;,&#x5982;&#x679C;&#x6253;&#x5F00;&#x8DF3;&#x5230;&#x6B65;&#x9AA4;8,&#x8FDB;&#x884C;&#x964D;&#x7EA7;&#x7B56;&#x7565;,&#x5982;&#x679C; &#x5173;&#x95ED;&#x8FDB;&#x5165;&#x6B65;&#x9AA4;.</p>
</li>
<li><p>&#x5224;&#x65AD;&#x7EBF;&#x7A0B;&#x6C60;/&#x961F;&#x5217;/&#x4FE1;&#x53F7;&#x91CF;&#x662F;&#x5426;&#x8DD1;&#x6EE1;&#xFF0C;&#x5982;&#x679C;&#x8DD1;&#x6EE1;&#x8FDB;&#x5165;&#x964D;&#x7EA7;&#x6B65;&#x9AA4;8,&#x5426;&#x5219;&#x7EE7;&#x7EED;&#x540E;&#x7EED;&#x9AA4;.</p>
</li>
<li><p>&#x8C03;&#x7528;HystrixCommand&#x7684;run&#x65B9;&#x6CD5;.&#x8FD0;&#x884C;&#x4F9D;&#x8D56;&#x903B;&#x8F91;&#xFF0C;&#x4F9D;&#x8D56;&#x903B;&#x8F91;&#x8C03;&#x7528;&#x8D85;&#x65F6;,&#x8FDB;&#x5165;&#x6B65;&#x9AA4;8.</p>
</li>
<li><p>&#x5224;&#x65AD;&#x903B;&#x8F91;&#x662F;&#x5426;&#x8C03;&#x7528;&#x6210;&#x529F;&#x3002;&#x8FD4;&#x56DE;&#x6210;&#x529F;&#x8C03;&#x7528;&#x7ED3;&#x679C;&#xFF1B;&#x8C03;&#x7528;&#x51FA;&#x9519;&#xFF0C;&#x8FDB;&#x5165;&#x6B65;&#x9AA4;8.</p>
</li>
<li><p>&#x8BA1;&#x7B97;&#x7194;&#x65AD;&#x5668;&#x72B6;&#x6001;,&#x6240;&#x6709;&#x7684;&#x8FD0;&#x884C;&#x72B6;&#x6001;(&#x6210;&#x529F;, &#x5931;&#x8D25;, &#x62D2;&#x7EDD;,&#x8D85;&#x65F6;)&#x4E0A;&#x62A5;&#x7ED9;&#x7194;&#x65AD;&#x5668;&#xFF0C;&#x7528;&#x4E8E;&#x7EDF;&#x8BA1;&#x4ECE;&#x800C;&#x5224;&#x65AD;&#x7194;&#x65AD;&#x5668;&#x72B6;&#x6001;.</p>
</li>
<li><p>&#x6CA1;&#x6709;&#x5B9E;&#x73B0;getFallback&#x7684;Command&#x5C06;&#x76F4;&#x63A5;&#x629B;&#x51FA;&#x5F02;&#x5E38;&#xFF1B;fallback&#x964D;&#x7EA7;&#x903B;&#x8F91;&#x8C03;&#x7528;&#x6210;&#x529F;&#x76F4;&#x63A5;&#x8FD4;&#x56DE;&#xFF1B;&#x964D;&#x7EA7;&#x903B;&#x8F91;&#x8C03;&#x7528;&#x5931;&#x8D25;&#x629B;&#x51FA;&#x5F02;&#x5E38;</p>
<p>getFallback()&#x964D;&#x7EA7;&#x903B;&#x8F91;.&#x4EE5;&#x4E0B;&#x56DB;&#x79CD;&#x60C5;&#x51B5;&#x5C06;&#x89E6;&#x53D1;getFallback&#x8C03;&#x7528;&#xFF1A;</p>
<p>&#x3000;&#x3000;(1) run()&#x65B9;&#x6CD5;&#x629B;&#x51FA;&#x975E;HystrixBadRequestException&#x5F02;&#x5E38;&#x3002;</p>
<p>&#x3000;&#x3000;(2) run()&#x65B9;&#x6CD5;&#x8C03;&#x7528;&#x8D85;&#x65F6;</p>
<p>&#x3000;&#x3000;(3) &#x7194;&#x65AD;&#x5668;&#x5F00;&#x542F;&#x62E6;&#x622A;&#x8C03;&#x7528;</p>
<p>&#x3000;&#x3000;(4) &#x7EBF;&#x7A0B;&#x6C60;/&#x961F;&#x5217;/&#x4FE1;&#x53F7;&#x91CF;&#x662F;&#x5426;&#x8DD1;&#x6EE1;</p>
</li>
<li><p>&#x8FD4;&#x56DE;&#x6267;&#x884C;&#x6210;&#x529F;&#x7ED3;&#x679C;</p>
</li>
</ol>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; mine 2022-2025 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2022-08-04 10:52:51
</span></footer>
<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="10.服务调用-OpenFeign.html" class="navigation navigation-prev " aria-label="Previous page: 服务调用-OpenFeign">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="12.网关-Gateway.html" class="navigation navigation-next " aria-label="Next page: 网关-Gateway">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"熔断器-Hystrix","level":"4.1.10","depth":2,"next":{"title":"网关-Gateway","level":"4.1.11","depth":2,"path":"springcloud/12.网关-Gateway.md","ref":"springcloud/12.网关-Gateway.md","articles":[]},"previous":{"title":"服务调用-OpenFeign","level":"4.1.9","depth":2,"path":"springcloud/10.服务调用-OpenFeign.md","ref":"springcloud/10.服务调用-OpenFeign.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["back-to-top-button","code","splitter","expandable-chapters-small","anchors","theme-comscore","tbfed-pagefooter","sidebar-style","pageview-count","popup"],"pluginsConfig":{"sidebar-style":{"author":"梁兴龙","title":"《Java 笔记本》"},"tbfed-pagefooter":{"copyright":"Copyright &copy mine 2022-2025","modify_label":"文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"splitter":{},"search":{},"popup":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"theme-comscore":{},"back-to-top-button":{},"pageview-count":{},"expandable-chapters-small":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"anchors":{}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"springcloud/11.熔断器-Hystrix.md","mtime":"2022-08-04T02:52:51.083Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2022-08-22T03:22:22.085Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sidebar-style/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

